package com.zxy.express.controller;

import com.autopai.base.common.web.constant.Constant;
import com.autopai.base.common.web.model.RestResult;
import com.autopai.base.common.web.page.PageData;
import com.autopai.base.common.web.validator.ValidatorUtils;
import com.autopai.base.common.web.validator.group.AddGroup;
import com.autopai.base.common.web.validator.group.DefaultGroup;
import com.autopai.base.common.web.validator.group.UpdateGroup;
import com.zxy.express.dto.PracticeRecordDTO;
import com.zxy.express.service.PracticeRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import springfox.documentation.annotations.ApiIgnore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 总练习记录表
 *
 * @author zhangxiying ${email}
 * @since ${version} 2025-07-01
 */
@RestController
@RequestMapping("practicerecord")
@Api(tags="总练习记录表")
public class PracticeRecordController {
    @Autowired
    private PracticeRecordService practiceRecordService;

    @GetMapping("page")
    @ApiOperation("分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
        @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String")
    })
    public RestResult<PageData<PracticeRecordDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<PracticeRecordDTO> page = practiceRecordService.page(params);

        return new RestResult<PageData<PracticeRecordDTO>>().ok(page);
    }

    @GetMapping("{id}")
    @ApiOperation("信息")
    public RestResult<PracticeRecordDTO> get(@PathVariable("id") String id){
        PracticeRecordDTO data = practiceRecordService.get(id);

        return new RestResult<PracticeRecordDTO>().ok(data);
    }

    @PostMapping("save")
    @ApiOperation("保存")
    public RestResult save(@RequestBody PracticeRecordDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);

        practiceRecordService.save(dto);

        return new RestResult();
    }

    @PutMapping
    @ApiOperation("修改")
    public RestResult update(@RequestBody PracticeRecordDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);

        practiceRecordService.update(dto);

        return new RestResult();
    }

    @DeleteMapping
    @ApiOperation("删除")
    public RestResult delete(@RequestBody String[] ids){
        //效验数据
       // AssertUtils.isArrayEmpty(ids, "id");

        practiceRecordService.delete(ids);

        return new RestResult();
    }

    @GetMapping("getPracticeStatis")
    @ApiOperation("获取统计信息")
    public RestResult<PracticeRecordDTO> getPracticeStatis(){
        return practiceRecordService.getPracticeStatis();
    }

    @GetMapping("getPracticeCalendar")
    @ApiOperation("获取练习日历")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "date", value = "yyyy-MM-dd", paramType = "query", required = true, dataType="String")
    })
    public RestResult<PracticeRecordDTO> getPracticeCalendar(@ApiIgnore @RequestParam Map<String, Object> params){
        return practiceRecordService.getPracticeCalendar(params);
    }

}